<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    </style>
</head>

<body>
        <button class="open" >开关</button>
    <script>
        var open = document.querySelector('.open')
        var flag =0; 
        open.onclick = function(){
            if(flag == 0){
                document.body.style.backgroundColor = 'black';
                flag = 1;
            }else{
                document.body.style.backgroundColor = '#fff';
                flag = 0;
            }
        }
    </script>
</body>
</html>